
#include "unzip_thread.h"

#include <JlCompress.h>
#include <QApplication>

UnZipThread::UnZipThread(QObject *parent)
        : QThread(parent)
{

}

UnZipThread::~UnZipThread()
{

}

UnZipThread &UnZipThread::instance()
{
    static UnZipThread instance;
    return instance;
}

void UnZipThread::run()
{
    sleep(3);
    QStringList list = JlCompress::extractDir("./update.zip", QApplication::applicationDirPath());
    if(list.isEmpty())
    {
        emit sig_unzipFinished(false);
        return;
    }
    QFile file("./data/version.dat");
    file.open(QIODevice::WriteOnly);
    file.write(current_name_.toLocal8Bit());
    file.close();

    QFile fileUpdate("./update.zip");
    fileUpdate.remove();
    QFile fileTemp("./update.zip_tmp");
    fileTemp.remove();
    emit sig_unzipFinished(true);
}

void UnZipThread::setName(const QString &name)
{
    current_name_ = name;
}
